package com.travel.controller.admin;

import com.travel.entity.dto.CarouselUploadDTO;
import com.travel.entity.po.Carousel;
import com.travel.result.PageResult;
import com.travel.result.Result;
import com.travel.service.CarouselService;
import com.travel.utils.Base64ToImg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:Jasenon_ce
 * @Date: 2025/03/13/下午2:24
 */
@Api(tags = "管理员接口")
@RestController
@RequestMapping("/admin/carousel")
@Slf4j
@CrossOrigin
public class AdminCarouselController {

    @Autowired
    private CarouselService carouselService;

    @Autowired
    private Base64ToImg base64ToImg;

    @ApiOperation("获取所有轮播图")
    @GetMapping("/list")
    public Result<List<Carousel>> getAllCarousels() {
        log.info("获取所有轮播图");
        List<Carousel> carousels = carouselService.getAllCarousels();
        return Result.success(carousels);
    }
    
    @ApiOperation("分页查询轮播图")
    @GetMapping("/page")
    public Result<PageResult<Carousel>> getCarouselsByPage(
            @ApiParam(value = "页码", required = false) @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量", required = false) @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        log.info("分页查询轮播图，页码：{}，每页数量：{}", pageNum, pageSize);
        PageResult<Carousel> pageResult = carouselService.getCarouselsByPage(pageNum, pageSize);
        return Result.success(pageResult);
    }

    @ApiOperation("上传轮播图")
    @PostMapping("/carouselUpload")
    public Result<?> addCarousel(@RequestBody CarouselUploadDTO carouselUploadDTO) {
        log.info("上传轮播图");
        Carousel carousel = new Carousel(carouselUploadDTO);
        carouselService.addCarousel(carousel);
        return Result.success();
    }
}
